﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Logging
{
    public class Log
    {
        private String _pathName;
        private String _url;
        private String _errorMessage;
        private String _stackTrace;

        private StreamWriter StrWer;
        private StreamReader StrRead;

        public void write_log()
        {
            String fullPathName = pathName + "Error.txt";
            String output = null;

            /*** Create Directory ***/
            if (Directory.Exists(pathName) == false)
            {
                DirectoryInfo dir = Directory.CreateDirectory(pathName);
            }

            /*** Create Text File ***/
            if (File.Exists(fullPathName) == false)
            {
                StrWer = File.CreateText(fullPathName);
                StrWer.Close();
            }

            /*** Read File ***/
            StrRead = File.OpenText(fullPathName);
            while (!(StrRead.EndOfStream))
            {
                output += StrRead.ReadLine() + Environment.NewLine;
            }
            StrRead.Close();

            /*** Write File ***/
            StrWer = File.CreateText(fullPathName);
            StrWer.WriteLine("****************************************************");
            StrWer.WriteLine("* ErrorDate : " + DateTime.Now);
            StrWer.WriteLine("* URL : " + url);
            StrWer.WriteLine("* ErrorMessage : " + errorMessage);
            StrWer.WriteLine("*");
            StrWer.WriteLine("* StackTrace : " + stackTrace);
            StrWer.WriteLine("****************************************************");
            StrWer.WriteLine(" ");
            StrWer.WriteLine(output);

            StrWer.Close();
        }

        public String pathName
        {
            get
            {
                return _pathName;
            }
            set
            {
                _pathName = value;
            }
        }

        public String url
        {
            get
            {
                return _url;
            }
            set
            {
                _url = value;
            }
        }

        public String errorMessage
        {
            get
            {
                return _errorMessage;
            }
            set
            {
                _errorMessage = value;
            }
        }

        public String stackTrace
        {
            get
            {
                return _stackTrace;
            }
            set
            {
                _stackTrace = value;
            }
        }
    }
}
